package docsync;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class AndroidFile implements FileInterface {
	File _file;

	public AndroidFile(String path) {
		_file = new File(path);
	}

	public AndroidFile(File f) {
		_file = f;
	}

	@Override
	public String getFilename() {
		return _file.getName();
	}

	@Override
	public String getIdentifier() {
		return getFilename();
	}

	@Override
	public long lastModify() {
		return _file.lastModified();
	}

	@Override
	public InputStream read() throws Exception {
		return new FileInputStream(_file);
	}

	@Override
	public void write(InputStream is, long length) throws Exception {
		OutputStream os = new FileOutputStream(_file);

		byte[] buffer = new byte[1024];
		int rct;
		while ((rct = is.read(buffer)) > 0) {
			os.write(buffer, 0, rct);
		}
		os.close();
		is.close();
	}

	@Override
	public long length() {
		return _file.length();
	}
	
	public File getFile(){
		return _file;
	}

}
